const chalk = require("chalk"); // 改变输出log颜色的工具
const log = (content) => console.log(chalk.green(content)); // 封装console
const path = require('path')
const fs = require('fs')

//判断文件夹是否存在 不存在创建
const createDirSync = (pathName) => {
  if (fs.existsSync(pathName)) return true;
  //path.dirname(path)获取c的父路径 a/b/c 
  if (createDirSync(path.dirname(pathName))) {
    fs.mkdirSync(pathName);
    return true;
  }
}
//写到对应文件夹
const writeToFile = (path, content) => {
  //判断文件夹是否存在 不存在创建
  return fs.promises.writeFile(path, content)//返回promise
}

module.exports = {
  writeToFile,
  createDirSync,
  log
}